Repository navigation
fix highlighter bugs - #4022
fix highlighter bugs#4022
Conversation
|
If it doesn't break anything else then yes. |
|
I hit this same bug from a different direction (a Since the open question here was "if it doesn't break anything else", and Verified on
|
JoeKar
left a comment
There was a problem hiding this comment.
Performs better in various use cases, where the actual implementation fails.
👍
|
Totally forgot about this but yeah, I haven't encountered any problem daily driving this PR. |
|
It would be nice if the commit message explained in a bit more detail what exact bugs this fixes and how exactly it fixes them (given that the highlighter code is by no means easy to understand). i.e.:
How exactly does it make them no longer fail?
What exactly is the issue and what exactly is the fix? (and BTW, if this is a separate issue, why is it in the same commit?) |
847ac7e to
7db5f77
Compare
|
I've updated the commit message to more accurately describe the changes, and added @Londopy 's test and one more. |
|
Thanks. Sounds like there are three separate fixes? Any chance to split them correspondingly into 3 commits, so that it is clearly seen which change fixes what? (The test also could be in its own commit.) Also I see it still only describes what problems it fixes, not how it fixes them. What exactly was the problem with ...Also please fix the gofmt issues in |
|
On the
So
@redsti-github feel free to use any of this in the commit message. |
7db5f77 to
bd8f77e
Compare
|
This comparison can help with the question "if it doesn't break anything else". For each built-in syntax file, I highlighted each matching file in the micro repository with
At the PR head, 105 of the 155 lines are better:
20 lines have no visible change. 30 lines are worse. All of them are XML lines where more tags follow a self-closing tag. An example is line 25 of rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defsOn |
|
Thank you for giving this a good test!
In my opinion, this is definitely an issue with I'd propose to change - identifier:
start: " "
end: "="
rules: []to - identifier: " [a-zA-Z0-9:_-]+=?"which appears to work correctly. (Though this change should probably be a seperate PR.) |
It is more trivial, but it doesn't highlight this valid XML any longer: <marker
id
=
"arrow">
[...]
</marker>A corrected version of the highlighter should do this. |
|
Ah, i forgot attributes can span multiple lines. - identifier:
start: "\\s[:A-Z_a-z]"
end: "="
rules: []should work. (Though xml spec allows attributes to start with certain unicode characters. I'm not sure how to handle that.) Either way, this bug is still a problem with |
|
Re commit messages again:
Not sure what this means. What exactly is the issue and how to reproduce it? Also, I assume by "format" you mean "highlight"? Or perhaps something else?
Again, could you give an example of what exactly was highlighted incorrectly? |
If there is a nested region inside another nested region (f.e. a text string within a html tag), then everything between the start of the outer region, to the start of the inner region just doesn't get highlighted. Look at this: Also check the added highlighter tests, the second one does this check (with a different example than this html one)
Yes.
Here, there is nothing that is highlighted incorrectly, but it's mostly just a small optimisation. Currently, regions will attempt to highlight everything from the start of the region, to the end of the line, and then throw away everything that is past the end of the region. |
I see. Could you add this explanation to the commit message? (In particular, please add e.g. this ...Also, why didn't it get highlighted? The commit message says "fixed by recursing to nested region only after formatting the current one" but why does the order matter? IOW, what exactly is the root cause?
Then makes sense to add that second test in the same commit as this fix (and the first test, correspondingly, in the same commit as the first fix), instead adding both tests in one separate commit? So that it is clear which test is related to which fix.
Could you add this info to the commit message? |
| if !statesOnly { | ||
| highlights[start+firstLoc[0]] = firstRegion.limitGroup | ||
| } | ||
| h.highlightEmptyRegion(highlights, start+firstLoc[1], canMatchEnd, lineNum, sliceStart(line, firstLoc[1]), statesOnly) |
There was a problem hiding this comment.
I see you removed this highlightEmptyRegion() call. Is it because you considered it redundant and pointless (even independently of this fix)?
It seems indeed redundant and pointless: it highlights the same exact range as the highlightRegion() call right below it? So, we first highlight it as an "empty" region i.e. pretending that firstRegion is nil, and then we overwrite this bogus highlighting with the correct highlighting in the below highlightRegion()? What's going on?
Actually it is a question to @JoeKar who added this highlightEmptyRegion() in 7e8ff8c#diff-16d0164b7fcc4350a9a7a5827b930e8de29487a35a3afa8d9e165b8e2af0f13aR161. What was the reason for it? And why was it correct to remove h.highlightRegion(highlights, start, false, lineNum, sliceEnd(line, firstLoc[0]), curRegion, statesOnly), replacing it with this highlightEmptyRegion()?
...Hmm, isn't this whole fix basically a revert of 7e8ff8c? @JoeKar what do you say?
There was a problem hiding this comment.
If I remember correctly, I introduced this back then to highlight potential current patterns as long as no further nested regions are available.
But to be honest: As I mentioned in another issue, I gave up trying to understand this highlighting logic and discarded it in favor of #3127 (which I more or less exchanged locally too).
There was a problem hiding this comment.
There was a problem hiding this comment.
No, 7e8ff8c just moved the "highlight the part that is past the end of the region and return" part to after "highlight the current region".
But it still has "highlight nested region and return" (lines 177-184) before "highlight the current region" (lines 186-205), which this change swaps.
There was a problem hiding this comment.
Ok, I see.
Still, what about my earlier question (I'm just curious): did you remove this highlightEmptyRegion() call because you considered it unneeded regardless of this change, or is this removal specifically related to this change?
BTW if the former, it would be probably better to do this removal in a separate commit before this one (for easier review, to not mix two different changes in the same commit)?
There was a problem hiding this comment.
I removed it because it looked either unnecesarry, or plain wrong (why are we highlighting the same region, twice, with different rules?).
Testing it now from the first commit in this PR (3098b61), i got it misbehaving with these rules:
rules:
- todo: "xxx"
- comment:
start: "//"
end: "$"
rules:
- identifier:
start: "<"
end: ">"
rules:
- todo: "todo"which given the following text:
xxx
// xxx < xxx >
highlights everything as you would expect, except for the last xxx, which gets todo instead of identifier, which it clearly shouldn't. (Because the "comment" region calls highlightEmptyRegion which highlights xxx as "todo".)
I'll split it out into it's own commit later today.
bd8f77e to
c4b946d
Compare
|
I updated up the commit messages a bit, hopefully they are less confusing now. (Thanks dmaluka for the feedback!, i'm still new to this contributing to open source thing) |
|
Could you also wrap the lines in the commit messages e.g. at max 72 characters each, to make them plain-text friendly? |
051bbda to
b7bc9eb
Compare
|
I added your changes. And, sigh, made a slight mess fixing merge conflicts (but i think i fixed it). |
|
Nit: regarding the commit message of the 1st commit: as you can see for example at https://github.com/micro-editor/micro/pull/4022/commits, the commit title is cut at "...line lengths and", since you wrapped the title line as well, not just the body. Git commit messages conventionally consist of a single title line (not wrapped) followed by a blank line and a message body (preferably wrapped, usually at 72 characters). I.e. we don't wrap commit titles but simply make them not too long (preferably, again, max 72 characters). In this particular case, "patterns within regions no longer fail on specific line lengths and columns (#4018)" is not extremely long (83 characters), so I'd be fine with keeping it as is. OTOH we can easily make it shorter by making it less verbose. In particular, no need for this "(#4018)". Those "(#...)" references that you see throughout micro's git log are not added by commit authors, they are added automatically by Github when merging PRs, and they reference PRs themselves, not issues fixed by those PRs. Instead, add "Fixes #4018" to the commit message body. BTW that will also make Github automatically close #4018 when this PR is merged. While we're at it, in commit messages it is also often preferred to describe what the patch does (i.e. what it fixes, or improves, or implements, etc), in the imperative mood, e.g.: "Fix smth ...". So we can improve these 3 commit titles e.g. as follows:
|
Fixes micro-editor#4018 `start` is an index into the entire line, while `line` is from the start of the region to the end of the line (and so is `endLoc`).
Region body should only be highlighted with that region's rules (call to `highlightRegion` below removed line), not with the empty region rules.
Previously `<a style="abcd" size=5></a>` would not highlight `style` in the `identifier` colour, because highlighting the nested region `"abcd"` would cause an early return before code for highlighting the current region was reached.
Mostly just a small optimisation; currently, regions will attempt to highlight everything from the start of the region to the end of the line, and then discard everything that was past the end of the region. This commit makes rules scan only inside of the region. As a side effect, `$` now matches the end of a region as well as the end of a line. I'm not aware of any current syntax rules that this would break. It also adds some nice symmetry between `$` and `^`, as `^` was already matching to the start of regions.
b7bc9eb to
7d1fc82
Compare
|
Those are much better commit messages, thank you! |
(new PR since i accidentally closed the old one (#4020), sorry)